﻿package doue.interactive{
	import caurina.transitions.Tweener;
	import flash.display.Sprite;
	import flash.display.MovieClip;
	import flash.events.MouseEvent;
	import flash.geom.Point;
	//import mc3;

	public class DragDropTweener extends MovieClip {

		//private var mc3_mc:mc3;
		private var offset:Point;

		public function DragDropTweener() {
			this.buttonMode=true;
			this.addEventListener(MouseEvent.MOUSE_DOWN,drag);
		}

		//Function Drag
		private function drag(event:MouseEvent):void {
			stage.addEventListener(MouseEvent.MOUSE_MOVE,drag_move);
			stage.addEventListener(MouseEvent.MOUSE_UP,drop);

			//把物件提到最上層
			this.parent.addChild(this);

			this.offset=new Point( -this.mouseX, -this.mouseY);
		}
		//Function Drag_move
		private function drag_move(event:MouseEvent):void {
			//use tweener
			Tweener.addTween(this,{x:stage.mouseX + this.offset.x, y:stage.mouseY + this.offset.y, time:1});

		}
		//Function Drop
		private function drop(event:MouseEvent):void {
			stage.removeEventListener(MouseEvent.MOUSE_MOVE,drag_move);
			stage.removeEventListener(MouseEvent.MOUSE_UP,drop);
		}
	}
}


//Use DocumentClass 的寫法


/*package doue.interactive{
import caurina.transitions.Tweener;
import flash.display.Sprite;
import flash.display.MovieClip;
import flash.events.MouseEvent;
import flash.geom.Point;

public class DragDropTweener extends MovieClip {
public var dragable_mc:MovieClip;

private var offset:Point;

public function DragDropTweener() {
dragable_mc.buttonMode=true;
dragable_mc.addEventListener(MouseEvent.MOUSE_DOWN,this.drag);
}

//Function
private function drag(e:MouseEvent) {
stage.addEventListener(MouseEvent.MOUSE_MOVE,this.drag_move);
stage.addEventListener(MouseEvent.MOUSE_UP,this.drop);
//把物件提到最上層
dragable_mc.parent.addChild(dragable_mc);

this.offset=new Point(- this.dragable_mc.mouseX,- this.dragable_mc.mouseY);
}
private function drag_move(e:MouseEvent) {
//use tweener
Tweener.addTween(dragable_mc,{x:this.mouseX + this.offset.x,y:this.mouseY + this.offset.y,time:1});

}
private function drop(e:MouseEvent) {
stage.removeEventListener(MouseEvent.MOUSE_MOVE,this.drag_move);
stage.removeEventListener(MouseEvent.MOUSE_UP,this.drop);
}
}
}*/